package com.example.qxfw.csnl.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.zy.WaterLoggingFcst;
import com.example.qxfw.common.entity.zy.WaterLoggingPointInfo;
import com.example.qxfw.csnl.service.NllsService;
import com.example.qxfw.mongodb.hy.service.DocFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Api(tags = "城市内涝--内涝历史")
@RestController
@CrossOrigin
@RequestMapping("/HistoryOfWaterloggingController")
public class HistoryOfWaterloggingController {
    @Autowired
    private NllsService nllsService;
    @Autowired
    private DocFileService docFileService;

    @ApiOperation("城市内涝--内涝历史-内涝预报查询")
    @GetMapping("/selectOfWaterLoggingFcst")
    public SysResult selectOfWaterLoggingFcst(String startTime, String endTime){
        List<WaterLoggingFcst> list = nllsService.selectOfWaterLoggingFcst(startTime, endTime);
        return SysResult.success(list);
    }

    @ApiOperation("城市内涝--内涝历史-产品id查询")
    @GetMapping("/getProductId")
    public SysResult getProductId(Integer docId,String docPath){
        Integer productId = nllsService.getProductId(docId, docPath);
        return SysResult.success(productId);

    }

    @ApiOperation("城市内涝--内涝历史-删除内涝历史")
    @GetMapping("/deleteProduct")
    public SysResult deleteProduct(Integer docId){
        try {
            WaterLoggingFcst waterLoggingFcst = nllsService.deleteProduct(docId);
            if (waterLoggingFcst!=null){
                return SysResult.success(waterLoggingFcst);
            } else {
                return SysResult.fail("删除失败");
            }
        } catch (Exception e){
            e.printStackTrace();
            System.err.println("内涝历史删除错误");
            return SysResult.fail("删除错误");
        }
    }

    @ApiOperation("城市内涝--内涝历史-详情查看")
    @GetMapping("/viewDetails")
    public SysResult viewDetails(int id){
        List<WaterLoggingPointInfo> list = nllsService.viewDetails(id);
        return SysResult.success(list);
    }

}
